package com.neegix.development.menu.infrastructure.repository.impl;

import com.neegix.application.query.NebulaSQL;
import com.neegix.base.PageVO;
import com.neegix.development.menu.application.assembler.MenuAssembler;
import com.neegix.development.menu.application.cqrs.query.MenuQueryRepository;
import com.neegix.development.menu.application.cqrs.query.condition.MenuWhereGroup;
import com.neegix.development.menu.application.dto.MenuDTO;
import com.neegix.development.menu.interfaces.vo.MenuVO;
import com.neegix.development.menu.infrastructure.repository.convert.MenuConverter;
import com.neegix.development.menu.infrastructure.repository.dataobject.MenuDO;
import com.neegix.development.menu.infrastructure.repository.mapper.MenuMapper;
import com.neegix.development.menu.infrastructure.repository.mapper.customized.MenuCustomizedMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

 /**
  * This file is auto-generated by nebula-framework-generator.
  * The auto-generation plugin was developed using IntelliJ IDEA Community Edition.
  * Thanks to JetBrains for their outstanding contributions to the developer community.
  * <p>
  * The code generated by this tool is owned by the user of the tool.
  * The tool itself is copyrighted by <a href="https://www.neegix.com">https://www.neegix.com</a>.
  *
  * @author <a href="https://www.neegix.com">https://www.neegix.com</a>
  * @version 1.0.0
  * @since 2024-11-21 16:19:51
  */

@Repository
public class MenuQueryRepositoryImpl implements MenuQueryRepository {

    @Autowired
    private MenuMapper menuMapper;

    @Autowired
    private MenuCustomizedMapper menuCustomizedMapper;

    @Override
    public Optional<MenuVO> findById(Long id) {
        MenuDO menuDO = menuMapper.selectByPrimaryKey(id);
        return Optional.ofNullable(MenuAssembler.INSTANCE.covertVO(MenuConverter.INSTANCE.covertDTO(menuDO)));
    }

    @Override
    public Integer selectCount(List<Long> ids) {
        return menuCustomizedMapper.selectCountByIds(ids);
    }

//    @Override
//    public PageVO<MenuVO> findPage(Integer currentPage, Integer pageSize, MenuDTO menuDTO) {
//        NebulaSQL nebulaSQL = new NebulaSQL();
//        nebulaSQL.createWhereGroups(MenuWhereGroup.class)
//           .andIdEqualTo(menuDTO.getId())
//           .andCreateTimeBetween(menuDTO.getStartCreateTime(),menuDTO.getEndCreateTime())
//           .andUpdateTimeBetween(menuDTO.getStartUpdateTime(),menuDTO.getEndUpdateTime())
//           .andCreateUserEqualTo(menuDTO.getCreateUser())
//           .andUpdateUserEqualTo(menuDTO.getUpdateUser())
//           .andPidEqualTo(menuDTO.getPid())
//           .andNameLikeTo(menuDTO.getName())
//           .andAccessLikeTo(menuDTO.getAccess())
//           .andTypeEqualTo(menuDTO.getType())
//           .andEnabledEqualTo(menuDTO.getEnabled())
//           .andDeletedEqualTo(menuDTO.getDeleted());
//
//        nebulaSQL.setPager(currentPage, pageSize);
//        List<MenuDO> result = menuMapper.selectList(nebulaSQL);
//        Long total = menuMapper.selectCount(nebulaSQL);
//        PageVO<MenuVO> page = new PageVO<>(currentPage, pageSize);
//        page.setTotal(total);
//        page.setResult(MenuAssembler.INSTANCE.covertVO(MenuConverter.INSTANCE.covertDTOS(result)));
//        return page;
//    }

     @Override
     public Optional<MenuVO> findByName(String name) {
        NebulaSQL nebulaSQL = new NebulaSQL();
        nebulaSQL.createWhereGroups(MenuWhereGroup.class).andNameEqualTo(name);
        MenuDO menuDO = menuMapper.selectOne(nebulaSQL);
        return Optional.ofNullable(MenuAssembler.INSTANCE.covertVO(MenuConverter.INSTANCE.covertDTO(menuDO)));
     }

     @Override
     public List<MenuVO> findList(MenuDTO menuDTO) {
        NebulaSQL nebulaSQL = new NebulaSQL();
        nebulaSQL.createWhereGroups(MenuWhereGroup.class).andNameLikeTo(menuDTO.getName());
        List<MenuDO> menuDOS = menuMapper.selectList(nebulaSQL);
        return MenuAssembler.INSTANCE.covertVO(MenuConverter.INSTANCE.covertDTOS(menuDOS));
     }
 }
